package com.health.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(description = "统一返回结果类")
public class R {

    @ApiModelProperty(value = "是否成功")
    private boolean flag;//执行结果，true成功 false失败
    @ApiModelProperty(value = "展示的数据")
    private Object data;//返回数据
    @ApiModelProperty(value = "错误信息")
    private String errMsg;//错误信息


    //提供一些方便的静态方法
    public static R success() {
        R r = new R();
        r.setFlag(true);
        return r;
    }

    public static R success(Object data) {
        R r = new R();
        r.setFlag(true);
        r.setData(data);
        return r;
    }

    public static R error(String errMsg) {
        R r = new R();
        r.setFlag(false);
        r.setErrMsg(errMsg);
        return r;
    }
}
